package cn.js.feign.fallback;


import cn.js.dto.User;
import cn.js.feign.UserFeignClient;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;


@Component
public class UserFeignClientFallback implements FallbackFactory<UserFeignClient> {

    @Override
    public UserFeignClient create(Throwable throwable) {
        return new UserFeignClient(){
            @Override
            public User getById(Long userId) {
                //打印异常信息，方便从控制台查看触发兜底的原因
                throwable.printStackTrace();
                return new User(userId, "null", "User服务不可用，返回兜底数据");
            }
        };
    }
}
